package com.dell.optimize;

import java.util.Date;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.widget.Toast;

public class Util {
	
	public static final String SETTINGS = "Settings";
	
	public static final String SIZE = "size";
	public static final String INTERVAL = "interval";
	public static final String ERR_MSG = "err";
	static Context context;
	public static void setContext(Context ctx){
		context = ctx;
	}
	void start(){
		
	}
	public static void startService() {
//	      Toast.makeText(context, " Service Started", Toast.LENGTH_LONG).show();

		context.startService(new Intent(context, DelayService.class));		
	}
	
	public static void stopService() {
//	      Toast.makeText(context, " Service Stopped", Toast.LENGTH_LONG).show();
		context.stopService(new Intent(context, DelayService.class));		
	}
	public static void restartService() {
		// TODO Auto-generated method stub
		context.stopService(new Intent(context, OptimizationService.class));		
		context.startService(new Intent(context, OptimizationService.class));		
	}
	
	/*public static void stopAllService() {
		// TODO Auto-generated method stub
		context.stopService(new Intent(context, OptimizationService.class));
		context.stopService(new Intent(context, TimerService.class));
		context.startService(new Intent(context, OptimizationService.class));		
	}*/
	
	
	 public static void logMe(String msg) {
		  SharedPreferences store = context.getSharedPreferences(Util.SETTINGS, 0);
			String prevMsg = store.getString(Util.ERR_MSG, "");
			
			SharedPreferences.Editor editor = store.edit();
			Date cal = new Date();
			editor.putString(Util.ERR_MSG,prevMsg+"\n"+cal.toString()+"::"+msg);
			
			editor.commit();
	}

}
